# Copyright 2022 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test")

yacl_cc_library(
    name = "rw",
    visibility = ["//visibility:public"],
    deps = [
        ":csv_reader",
        ":csv_writer",
    ],
)

yacl_cc_library(
    name = "interface",
    hdrs = [
        "reader.h",
        "schema.h",
        "writer.h",
    ],
    visibility = ["//visibility:public"],
    deps = ["//yacl/io/stream:interface"],
)

yacl_cc_library(
    name = "float",
    hdrs = ["float.h"],
    visibility = ["//visibility:public"],
    deps = ["@com_google_absl//absl/strings"],
)

yacl_cc_library(
    name = "csv_reader",
    srcs = ["csv_reader.cc"],
    hdrs = ["csv_reader.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":float",
        ":interface",
        ":mmapped_file",
        "//yacl/base:exception",
        "//yacl/io/stream",
        "@com_github_fmtlib_fmt//:fmtlib",
        "@com_google_absl//absl/strings",
    ],
)

yacl_cc_library(
    name = "csv_writer",
    srcs = ["csv_writer.cc"],
    hdrs = ["csv_writer.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":float",
        ":interface",
        "//yacl/base:exception",
        "//yacl/io/stream",
        "@com_github_fmtlib_fmt//:fmtlib",
    ],
)

yacl_cc_library(
    name = "mmapped_file",
    srcs = ["mmapped_file.cc"],
    hdrs = ["mmapped_file.h"],
    deps = [
        "//yacl/base:exception",
        "@com_google_absl//absl/base:malloc_internal",
        "@com_google_absl//absl/cleanup",
    ],
)

yacl_cc_test(
    name = "csv_test",
    srcs = ["csv_test.cc"],
    deps = [
        ":rw",
    ],
)

yacl_cc_test(
    name = "rw_test",
    srcs = ["rw_test.cc"],
    data = [
        "//yacl/io/test/data:perfect_logit",
    ],
    deps = [
        ":rw",
        "//yacl/utils:elapsed_timer",
        "@com_github_gflags_gflags//:gflags",
        "@com_google_absl//absl/strings",
    ],
)
